package com.miyake.server.servlet;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class MyXmlParser {
	private Integer length;
	private String bin;
	public MyXmlParser(InputStream is) {

		try {
			BufferedInputStream bis = new BufferedInputStream(is);
			DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
			DocumentBuilder builder = dbfactory.newDocumentBuilder();
			Document doc = builder.parse(bis);
			Element root = doc.getDocumentElement();
			
			NodeList data = root.getElementsByTagName("Data");
			String i = ((Element)root.getElementsByTagName("Length").item(0)).getTextContent();
			this.length = Integer.valueOf(i);
			bin = ((Element)root.getElementsByTagName("Bin").item(0)).getTextContent();

		} catch (ParserConfigurationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SAXException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public Integer getLength() {
		return length;
	}
	public String getBin() {
		return bin;
	}
	
}
